<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    setTimeout(function() {
        var a = ' hello'
        setTimeout(function() {
            var b = ' lagou'
            setTimeout(function() {
                var c = 'I ❤️ U'
                console.log(a + b + c)
            }, 10);
        }, 10);
    }, 10);
    /* 
      分析: 这是一个setTimeout嵌套问题, 且每次执行完后, 上一个指会传递给下一个
      优化: 使用Promise的链式调用并对每个then方法保存上一个值并且与当前值相加并手动返回
    */

    function getValue(value) {
      let val = ''
      setTimeout(() => {
        val = value
      }, 10);
      return value
    }

  Promise.resolve()
    .then(value=> getValue('hello '))
    .then(value=> getValue(value + 'lagou ') )
    .then(value=> console.log(getValue(value +' I ❤️ U')) )
  </script>
</body>
</html>